Repository navigation
Fix two normalize() collisions between structurally different resources - #406
Merged
Merged
Conversation
A percent-encoded `/` (%2F) in the path was decoded into a literal `/` by normalize(), making it indistinguishable from an actual path separator, e.g. "/foo%2Fbar" (one segment) and "/foo/bar" (two segments) both normalized to the same ZIM path. It is now kept encoded (as %2F). A literal `_.`/`_..` segment (already of the escaped form used for an actual `.`/`..` dot-segment) was left untouched by escape_dot_segments(), colliding with the escaped form of an actual dot-segment, e.g. a literal "_." segment and an unresolved "." dot-segment both normalized to "_.". escape_dot_segments() now escapes such a segment with one more leading `_`, forming a ladder (`.` -> `_.`, literal `_.` -> `__.`, literal `__.` -> `___.`, ...) that never collides across levels. The third collision raised in #396 (`+`/`%20`/raw space in the query string all collapsing to the same stored space) is intentionally left as-is: all three are HTTP-query-string equivalent, and get_document_uri() already re-encodes the stored space back to %20 when building the actual rewritten URL, so no information that matters is lost.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #406 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 42 42
Lines 2954 2958 +4
Branches 453 453
=========================================
+ Hits 2954 2958 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses the first item of #396's plan (the three
normalize()/escape_dot_segments()fixes), for the two that are genuine content collisions with no acceptable workaround:/(%2F) in the path was decoded into a literal/bynormalize(), making it indistinguishable from an actual path separator:/foo%2Fbar(one segment, containing a literal/) and/foo/bar(two segments) both normalized to the same ZIM path. It is now kept encoded (as%2F)._./_..segment (already of the escaped form used for an actual./..dot-segment) was left untouched byescape_dot_segments(), colliding with the escaped form of an actual dot-segment.escape_dot_segments()now escapes such a segment with one more leading_, forming a ladder (.→_., literal_.→__., literal__.→___., ...) that never collides across levels.The third collision raised in #396 (
+/%20/raw space in the query string all collapsing to the same stored space) is intentionally left as-is: all three are HTTP-query-string equivalent, andget_document_uri()already re-encodes the stored space back to%20when building the actual rewritten URL, so no information that matters is lost.